
//***********************************************
//
//      Filename: SEnc.java
//
//        Author: wwb
//        Mails: 1274860621@qq.com
//        Create: 2018-06-13 22:17:01
// Last Modified: 2018-06-13 22:17:01
//***********************************************
import javax.crypto.Cipher;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.security.Key;

public class SEnc {
    public SEnc(){}
    public String jiami(String s) throws Exception{
        FileInputStream f=new FileInputStream("key1.dat");
        ObjectInputStream b=new ObjectInputStream(f);
        Key k=(Key)b.readObject( );
        Cipher cp=Cipher.getInstance("DESede");
        cp.init(Cipher.ENCRYPT_MODE, k);
        byte ptext[]=s.getBytes("UTF8");
        for(int i=0;i<ptext.length;i++){
            System.out.print(ptext[i]+",");
        }
        System.out.println("");
        byte ctext[]=cp.doFinal(ptext);
        String a="";
        for(int i=0;i<ctext.length;i++){
            a+=ctext[i] +",";
            //    System.out.print(a);
        }
        FileOutputStream f2=new FileOutputStream("SEnc.dat");
        f2.write(ctext);
        return a;
    }
}
